	var align_array=[{text: '左对齐',value:'left'},{text: '居中',value:'center'},{text: '右对齐',value:'right'},{text: '默认',value:'null'}];
	var hidden_array=[{text: '显示',value:'false'},{text: '隐藏',value:'true'},{text: '默认',value:'null'}];
	var prefix_array=[{text: '$',value:'$'},{text: '#',value:'#'},{text: '￥',value:'￥'},{text: '无',value:'null'}];
	var suffix_array=[{text: '%',value:'%'},{text: '^',value:'^'},{text: '*',value:'*'},{text: '无',value:'null'}];
Ext.onReady(function(){
	function number(){
		return document.getElementById('droppableH').childNodes[0].childNodes.length;
	}
	function insertText(textarea,text)
	{
	    var tc = Ext.getDom(textarea);
	    var tclen = tc.value.length;
	    tc.focus();
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = text;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+text+tc.value.substring(tc.selectionStart,tclen));
	    }
	    //tc.focus();
	}
	var editPanel = new Ext.TabPanel({
		id:'editPanel',
        activeTab: 0,
        height:230,
		border:false,
		style: 'position:absolute;left:0;bottom:0;z-index:101',
		collapsible: true,
		animCollapse: true,
        defaults:{autoScroll: true},
        items:[new Ext.Panel({
    	id:'zhibiao_message',
    	evObject:null, //正在修改的Li-dom对象
    	title:'指标信息',
		frame:true,
		border:false,
		bodyStyle :'border:none',
        tbar: [{
            xtype: 'buttongroup',
            title: '基本功能',
       //     columns: 2,
            defaults: {
                scale: 'small'
            },
            items: [ {	iconCls:'newMeasure',
				text:'新    建',
				handler:function(){
            		Ext.getCmp('zhibiao_message').evObject = null;
            		Ext.getCmp('measureLabel').setValue('');
            		Ext.getCmp('measureExpress').setValue('');
            		this.getEl().dom.style.border = '0px';
				}
            },{
				id:'submit_btn',
				iconCls:'submit',
				text:'提    交',
				handler:function(){
	            	var label = Ext.getCmp('measureLabel').getValue();
	        		var express = Ext.getCmp('measureExpress').getValue();
	        		if(label.trim() == ''){
	        			alert('指标名称不能为空');
	        			Ext.getCmp('measureLabel').focus();
	        			return;
	        		}else if(express.trim() == ''){
	        			alert('指标表达式不能为空');
	        			Ext.getCmp('measureExpress').focus();
	        			return;
	        		}
            		if(Ext.getCmp('zhibiao_message').evObject != null){ 
            			//ev不为空,是修改操作
	            		Ext.getCmp('zhibiao_message').evObject.label=Ext.getCmp('measureLabel').getValue();
	            		Ext.getCmp('zhibiao_message').evObject.column=Ext.getCmp('measureExpress').getValue();
	            		Ext.getCmp('zhibiao_message').evObject.innerText = Ext.getCmp('measureLabel').getValue();
	            		Ext.getCmp('zhibiao_message').evObject.customH = 'true';
            		}else{
            			//是新建操作
            			 var li = jQuery("<li oncontextmenu='showmenu(this)'/>");
						 li.attr("id",'column'+number());
						 li.attr("isAdvanceModel",'true');
						 li.attr("label",Ext.getCmp('measureLabel').getValue());
						 li.attr("column",Ext.getCmp('measureExpress').getValue());
						 li.text(Ext.getCmp('measureLabel').getValue());
						 li.attr("customH",'true');
						 li.addClass('h');
						 jQuery("#droppableH").find('ul').append(li);
						 Ext.getCmp('zhibiao_message').evObject = li.get(0);
            		}
            		this.getEl().dom.style.border = '0px';
				}
            },{
				iconCls:'hide',
				text:'隐    藏',
				handler:function(){
            		Ext.getCmp('editPanel').collapse();
				}
            },{
				text:'函数库',
				iconCls:'fn',
				handler:function(){
	            	var fntools = new Ext.ux.FnTools({submit:function(res){
						if(Ext.getCmp('editPanel').getActiveTab() === Ext.getCmp('zhibiao_message')){
							insertText('measureExpress',res);
						}else if(Ext.getCmp('editPanel').getActiveTab() == Ext.getCmp('allconditions')){
							insertText('conditions_textarea',res);
						}else if(Ext.getCmp('editPanel').getActiveTab() == Ext.getCmp('weidu_message')){
							insertText('weiduExpress',res);
					}
					}});
					fntools.show();
				}
            }]
        },{
            xtype: 'buttongroup',
            title: '操作功能',
           // columns:3,
            defaults: {
                scale: 'small'
            },
            items: [{
                xtype:'splitbutton',
                id:'button_align',
                text: '对齐方式',
                iconCls:'newMeasure',
                width:100,
                menu: {
            			items:align_array,
            			listeners:{
            			click:function(menu,menuItem){
            					if(Ext.getCmp('zhibiao_message').evObject!=null)
            					{
            						if(menuItem.value=='null')
            						{
            							Ext.getCmp('button_align').setText('对齐方式');
            						}else{	
	            						Ext.getCmp('button_align').setText(menuItem.text);
            						}
            						Ext.getCmp('zhibiao_message').evObject.align=menuItem.value;
            					}else{
            						Ext.Msg.alert('提示','尚未选择要操作的指标');
            					}
            				}
            		  }},
            	handler:function(){this.showMenu();}	
            },{
                xtype:'splitbutton',
                text: '显示方式',
                id:'button_hidden',
                iconCls:'newMeasure',
                width:100,
                menu: {
        			items:hidden_array,
        			listeners:{
            			click:function(menu,menuItem){
            					if(Ext.getCmp('zhibiao_message').evObject!=null)
            					{
            						if(menuItem.value=='null')
            						{
            							Ext.getCmp('button_hidden').setText('显示方式');
            						}else{					
	            						Ext.getCmp('button_hidden').setText(menuItem.text);
            						}
            						Ext.getCmp('zhibiao_message').evObject.hidden=menuItem.value;
            					}else{
            						Ext.Msg.alert('提示','尚未选择要操作的指标');
            					}
            				}
            		  }
            	},
            	handler:function(){this.showMenu();}
            },{
                text: '前缀',
                iconCls:'newMeasure',
                id:'button_prefix',
                width:100,
                menu: {
        			items:prefix_array,
        			listeners:{
			    			click:function(menu,menuItem){
							if(Ext.getCmp('zhibiao_message').evObject!=null)
							{
								if(menuItem.value=='null')
								{
									Ext.getCmp('button_prefix').setText('前缀');
								}else{					
									Ext.getCmp('button_prefix').setText(menuItem.text);
								}
								Ext.getCmp('zhibiao_message').evObject.prefix=menuItem.value;
							}else{
								Ext.Msg.alert('提示','尚未选择要操作的指标');
							}
						}
        		  }},
        		handler:function(){this.showMenu();}
            },{
                text: '后缀',
                iconCls:'newMeasure',
                id:'button_suffix',
                width:100,
                menu: {
        			items:suffix_array,
        			listeners:{
		            	click:function(menu,menuItem){
						if(Ext.getCmp('zhibiao_message').evObject!=null)
						{
							if(menuItem.value=='null')
							{
								Ext.getCmp('button_suffix').setText('后缀');
							}else{			
								Ext.getCmp('button_suffix').setText(menuItem.text);
							}
							Ext.getCmp('zhibiao_message').evObject.suffix=menuItem.value;
						}else{
							Ext.Msg.alert('提示','尚未选择要操作的指标');
						}
					}}
            	},
            	handler:function(){this.showMenu();}
            },{
            	text:'宽度:',
            	iconCls:'newMeasure',
            	handler:function(){Ext.getCmp('c_width').getEl().dom.style.border = '1px solid red'}
            },
            {         
                xtype: 'numberfield',//spinnerfield
        		id:'c_width',
                minValue: 0,
                align:'left',
                width:50,
                   //  	allowDecimals: true,
                   //   	decimalPrecision: 1,
                  //    	alternateIncrementValue: 2.1,
                accelerate: true ,           
        		listeners:
	            {change:function(f,newvalue,oldvalue){
	        			if(Ext.getCmp('zhibiao_message').evObject!=null){
	        				if(Ext.getCmp('c_width').value=='')
	        				{
	        					Ext.getCmp('zhibiao_message').evObject.width='100';
	        				}else{
	        					Ext.getCmp('zhibiao_message').evObject.width=Ext.getCmp('c_width').value;
	        				}
	        			}else{	Ext.Msg.alert('提示','尚未选择要操作的指标');	}
	        			Ext.getCmp('c_width').getEl().dom.style.border = '1px solid';
        		}}
            }
 //           ,{  
 //           	text: '测试',
 //               iconCls:'newMeasure',
 //           	handler:function()
 //           	{
 //           	var r=Ext.getCmp('zhibiao_message').evObject
 //           	alert(r.hidden+r.width);
 //           	}
  //          }
            ]
        }],
		items:[{
            xtype:'panel',
            bodyStyle:'border:none',
            layout:'hbox',
            layoutConfig: {
                padding: 10
            },
            defaults:{
                margins:'0 5 0 0'
            },
            items:[{
			layout:'border',
			bodyStyle:'border:none;',
			height:125,
			items:[{
				region:'center',
	            xtype:'fieldset',
	            title: '当前指标',
	            collapsible: true,
	            autoHeight:true,
	            layout:'form',
	            items:[{
	            	id:'measureLabel',
					xtype:'textfield',
					fieldLabel:'指标名称',
					blankText:'名称不可为空',
					enableKeyEvents:true,
					anchor:'100%',
					listeners:{
	            		keydown:function(){
						Ext.getCmp('submit_btn').getEl().dom.style.border = '1px solid red';
						},
						change:function(){
		            		Ext.getCmp('submit_btn').getEl().dom.style.border = '1px solid red';
		            	}}
				},{
					id:'measureExpress',
					xtype:'textarea',
					fieldLabel:'指标表达式',
					blankText:'表达式不可为空',
					enableKeyEvents:true,
					height:50,
					anchor:'100%',
					listeners:{
					keydown:function(){
						Ext.getCmp('submit_btn').getEl().dom.style.border = '1px solid red';
					},
					change:function(){
						Ext.getCmp('submit_btn').getEl().dom.style.border = '1px solid red';
					}}
				}]
			},{
				region:'center',
	            split:true,
	            region:'east',
	            width:230,
	            bodyStyle:'border:none',
	            html:'<div id="operateBtn"><button/>1</button><button/>2</button><button/>3</button><button/>+</button><button/>(</button><button/>)</button><br>'+
				 	 '<button/>4</button><button/>5</button><button/>6</button><button/>-</button><button/><</button><button/>></button><br>'+
				 	 '<button/>7</button><button/>8</button><button/>9</button><button/>*</button><button/>[]</button><button/>|</button><br>'+
				 	 '<button/>0</button><button/>.</button><button/>=</button><button/>/</button><button/>,</button><button/>\'</button></div>'
			}]
            }]
		}]
    }),new Ext.Panel({
    	id:'allconditions',
    	title:'查询条件',
		frame:true,
		border:false,
		bodyStyle :'border:none',
		items:[{
            xtype:'panel',
            bodyStyle:'border:none',
            layout:'hbox',
            layoutConfig: {
                padding: 10
            },
            defaults:{
                margins:'0 5 0 0'
            },
            items:[{
				xtype:'button',
				iconCls:'hide',
				text:'隐    藏',
				handler:function(){
            		Ext.getCmp('editPanel').collapse();
				}
            },{
				xtype:'button',
				text:'函数库',
				iconCls:'fn',
				handler:function(){
	            	var fntools = new Ext.ux.FnTools({submit:function(res){
						if(Ext.getCmp('editPanel').getActiveTab() === Ext.getCmp('zhibiao_message')){
							insertText('measureExpress',res);
						}else if(Ext.getCmp('editPanel').getActiveTab() == Ext.getCmp('allconditions')){
							insertText('conditions_textarea',res);
						}
					}});
					fntools.show();
				}
            }]
		},{
			layout:'border',
			bodyStyle:'border:none;',
			height:125,
			items:[{
	            xtype:'fieldset',
	            title: '当前条件',
	            collapsible: true,
	            autoHeight:true,
	            layout:'form',
	            region:'center',
	            items:[{
					id:'conditions_textarea',
					xtype:'textarea',
					fieldLabel:'条件表达式',
					blankText:'表达式不可为空',
					enableKeyEvents:true,
					height:85,
					anchor:'100%',
					listeners:{afterrender:function(){
						//邦定拖拽到查询条件
						new Ext.dd.DropTarget(Ext.getCmp('conditions_textarea').getEl().dom, {
							ddGroup: 'DDGroup',
							copy: false,
							notifyDrop: function(ddSource, e, data){
							node = ddSource.dragData.node;
							var a=Ext.getCmp('conditions_textarea');
							if(node.attributes.d == 'h'){
								a.setValue(a.getValue()+'$'+node.attributes.table+'.'+node.attributes.column);
							}else if(node.attributes.d == 'v'){
								if(node.attributes.val.indexOf("[tree]") == -1){
									a.setValue(a.getValue()+' and $'+node.attributes.table+'.'+node.attributes.column + " = '" + node.attributes.val + "'");
								}else{
									a.setValue(a.getValue()+' and $'+node.attributes.tableName+'.'+node.attributes.column + " like '" + node.attributes.pid + "%'");
								}
							}
							return(true);
						}
						});
						//回显全局条件
						Ext.getCmp('conditions_textarea').setValue(jQuery("#globleConditions").text());
					}}
				}]
			},{
				region:'center',
	            split:true,
	            region:'east',
	            width:230,
	            bodyStyle:'border:none',
	            html:'<div id="conditionBtn"><button/>1</button><button/>2</button><button/>3</button><button/>+</button><button/>(</button><button/>)</button><br>'+
				 	 '<button/>4</button><button/>5</button><button/>6</button><button/>-</button><button/><</button><button/>></button><br>'+
				 	 '<button/>7</button><button/>8</button><button/>9</button><button/>*</button><button/>[]</button><button/>|</button><br>'+
				 	 '<button/>0</button><button/>.</button><button/>=</button><button/>/</button><button/>,</button><button/>\'</button></div>',
				listeners:{afterrender:function(){
					//给条件的小键盘绑定样式和事件
					jQuery('#conditionBtn > button').css("padding",'2px').css('width','30px');
					jQuery('#conditionBtn > button').click(function(){
						insertText('conditions_textarea',jQuery(this).text());
					});
				}}
			}]}
	       ],
	       listeners:{afterrender:function(){
				Ext.getCmp('editPanel').doLayout();
			}}
	       
    })],
    listeners:{expand:function(){
        	Ext.getCmp('allconditions').doLayout();
    }}
	});

	editPanel.render(Ext.getCmp('grid').getEl());
	editPanel.collapse(false);
	
	//给指标的小键盘绑定样式和事件
	jQuery('#operateBtn > button').css("padding",'2px').css('width','30px');
	jQuery('#operateBtn > button').click(function(){
		insertText('measureExpress',jQuery(this).text());
		Ext.getCmp('submit_btn').getEl().dom.style.border = '1px solid red';
	});
	
	//邦定拖拽到指标信息
	new Ext.dd.DropTarget(Ext.getCmp('measureExpress').getEl().dom, {
		ddGroup: 'DDGroup',
		copy: false,
		notifyDrop: function(ddSource, e, data){
		node = ddSource.dragData.node;
		var a=Ext.getCmp('measureExpress');
		if(node.attributes.d == 'h'){
			a.setValue(a.getValue()+'$'+node.attributes.table+'.'+node.attributes.column);
		}else if(node.attributes.d == 'v'){
			if(node.attributes.val.indexOf("[tree]") == -1){
				a.setValue(a.getValue()+'$'+node.attributes.table+'.' + node.attributes.val);
			}else{
				a.setValue(a.getValue()+'$'+node.attributes.tableName+'.' + node.attributes.pid);
			}
		}
		Ext.getCmp('submit_btn').getEl().dom.style.border = '1px solid red';
		return(true);
	}
	});
//	zhibiao_message.resizer = new Ext.Resizable(zhibiao_message.el, {
//        minHeight:50,
//        handles: "n",
//        pinned: true,
//        transparent:true,
//        resizeElement : function(){
//            var box = this.proxy.getBox();
//            this.proxy.hide();
//            zhibiao_message.setHeight(box.height);
//            return box;
//        }
//    });
})

function evchange()
	{
			var suf=Ext.getCmp('zhibiao_message').evObject.suffix;
			var pre=Ext.getCmp('zhibiao_message').evObject.prefix;
			var hid=Ext.getCmp('zhibiao_message').evObject.hidden;
			var ali=Ext.getCmp('zhibiao_message').evObject.align;
			var wid=Ext.getCmp('zhibiao_message').evObject.width;
			if(!(wid==undefined||wid=='null'))
			{
				Ext.getCmp('c_width').setValue(wid);
			}else{
				Ext.getCmp('c_width').setValue('');
			}
			if(ali==undefined||ali=='null')
			{
				Ext.getCmp('button_align').setText('对齐方式');
			}else{			
				for(var i=0;i<align_array.length;i++)
				{
					if(align_array[i]['value']==ali)
					{
						Ext.getCmp('button_align').setText(align_array[i]['text']);
						break;
					}
				}	
			}
			if(hid==undefined||hid=='null')
			{
				Ext.getCmp('button_hidden').setText('显示方式');
			}else{			
				for(var i=0;i<hidden_array.length;i++)
				{
					if(hidden_array[i]['value']==hid)
					{
						Ext.getCmp('button_hidden').setText(hidden_array[i]['text']);
						break;
					}
				}	
			}
			if(pre==undefined||pre=='null')
			{
				Ext.getCmp('button_prefix').setText('前缀');
			}else{			
				for(var i=0;i<prefix_array.length;i++)
				{
					if(prefix_array[i]['value']==pre)
					{
						Ext.getCmp('button_prefix').setText(prefix_array[i]['text']);
						break;
					}
				}	
			}
			if(suf==undefined||suf=='null')
			{
				Ext.getCmp('button_suffix').setText('后缀');
			}else{			
				for(var i=0;i<suffix_array.length;i++)
				{
					if(suffix_array[i]['value']==suf)
					{
						Ext.getCmp('button_suffix').setText(suffix_array[i]['text']);
						break;
					}
				}	
			}
	}